#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void join( int nextIndexs[], int preIndexs[], int index1, int index2)
{
	while( nextIndexs[index1] != -1)
		index1 = nextIndexs[index1];
	
	while( preIndexs[index2] != -1 )
		index2 = preIndexs[index2];
		
	nextIndexs[index1] = index2;
	preIndexs[index2] = index1;
}

void sortIndexs(int array[], int length)
{
	int index;
	for(int i=0; i<length-1; i++)
	{
		index = i;
		for(int j=i+1; j<length; j++)
			if(array[index] > array[j])
				index = j;
		
		if(index != i)
		{
			int t = array[i];
			array[i] = array[index];
			array[index] = t;
		}
	}
}

void sort(char array[], int length)
{

	int index;
	for(int i=0; i<length-1; i++)
	{
		index = i;
		for(int j=i+1; j<length; j++)
			if(array[index] > array[j])
				index = j;
		
		if(index != i)
		{
			char c = array[i];
			array[i] = array[index];
			array[index] = c;
		}
	}
	
}



void mainFunc(  char str[], int nextIndexs[], int preIndexs[], int length, char sortArray[], int indexsSort[] )
{
	for( int i=0; i<length; i++ )
	{
		if(preIndexs[i]!=-1 || nextIndexs[i]==-1)
			continue;
		
		int index = 0;
		int t = i;
		
		while( t != -1)
		{
			sortArray[index] = str[t];
			indexsSort[index] = t;
			
			t = nextIndexs[t];
			index++;			
		}
		
		sort( sortArray, index );
		sortIndexs( indexsSort, index );
		
		for( int k=0; k<index; k++ )
		{
			str[indexsSort[k]] = sortArray[k];
		}
	}
}


int main()
{
	char *str        = new char[10001];
	char *sortArray  = new char[10000];
	int  *indexSort  = new  int[10000];
	int  *nextIndexs = new  int[10000];
	int  *preIndexs  = new  int[10000];
	
	int length, n, x, y;
	
	while( scanf("%s", str) != EOF)
	{
		length = strlen( str );
		for(int i=0; i<length; i++)
		{
			nextIndexs[i] = preIndexs[i] = -1;
		}
		
		scanf("%d", &n);
		
		for(int k=0; k<n; k++)
		{
			scanf("%d", &x);
			scanf("%d", &y);
			
			int t = x;
			bool isFind = false;
			
			while( preIndexs[t] != -1 )
			{
				if(preIndexs[t] == y)
				{
					isFind = true;
					break;
				}
				t = preIndexs[t];
			}
			
			t = x;
			while( !isFind && nextIndexs[t]!=-1)
			{
				if(nextIndexs[t] == y)
				{
					isFind = true;
					break;
				}
				
				t = nextIndexs[t];
			}
			
			if( !isFind )
				join(nextIndexs, preIndexs, x, y);
		}
		mainFunc(str, nextIndexs, preIndexs, length, sortArray, indexSort );
		printf("%s\n", str);
	}
	
}